#include "main.h"

/* 使能外设时钟*/
void clk_enable(void)
{
    CCM_CCGR1 = 0xffffffff;
    CCM_CCGR2 = 0xffffffff;
    CCM_CCGR3 = 0xffffffff;
    CCM_CCGR4 = 0xffffffff;
    CCM_CCGR5 = 0xffffffff;
    CCM_CCGR6 = 0xffffffff;
}

/* 初始化LED*/
void led_init(void)
{
    SW_MUX_GPIO1_IO03 = 0x5; /* 服用为GPIO——IO03*/
    SW_PAD_GPIO1_IO03 = 0x10B0; /* 设置GPIO_IO03的电器属性*/

    /* GPIO初始化*/
    GPIO1_GDIR = 0x8;           /* 设置为输出*/
    GPIO1_DR   = 0x0;           /* 打开LED灯*/
}

void delay_short(volatile unsigned int n)
{
    while (n--)
    {
        /* code */
    }
    
}

void delay(volatile unsigned int n)
{
    while (n--)
    {
      delay_short(0x7ff);
    }
    
}

void led_on(void)
{
    GPIO1_DR &= ~(1<<3);
}

/* 关闭LED灯*/
void led_off(void)
{
    GPIO1_DR |= (1<<3);     /*bit3置一*/
}

int main(void)
{
    clk_enable();
    led_init();
    /* 初始化LED*/

    /* 设置LED闪烁*/
	while(1)			/* 死循环 				*/
	{	
		led_off();		/* 关闭LED   			*/
		delay(500);		/* 延时大约500ms 		*/

		led_on();		/* 打开LED		 	*/
		delay(500);		/* 延时大约500ms 		*/
	}
    return 0;
}